package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo9 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection()){
            connection.setAutoCommit(false);
            String sql = """
                    INSERT INTO userinfo(username,password,nickname,age)
                    VALUES ('李五','123','老五',18)""";
            Statement statement = connection.createStatement();
            statement.executeUpdate(sql);
            System.out.println("插入完毕");
            ResultSet resultSet = statement.executeQuery("SELECT username FROM userinfo");
            while (resultSet.next()){
                System.out.println( resultSet.getString("username"));
            }
            connection.commit();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
